<template>
    <el-input v-model="orgName" @focus="noFocus" ref="noFocus">
        <i class="el-icon-document-copy" slot="suffix" @click="clientSelect" v-if="edit"> </i>
    </el-input>
</template>

<script>
// eslint-disable-next-line no-unused-vars
import { selectDataClient, openAppClient } from '@/utils/common.js'
import { mapMutations } from 'vuex'

export default {
    props: {
        orgId: {
            type: String,
            default: ''
        },
        orgName: {
            type: String,
            default: ''
        },
        SelectedIDs: {
            type: Array,
            default: function () {
                return []
            }
        },
        edit: {
            type: Boolean,
            default: true
        },
        type: {
            type: String,
            default: 'getChildrenOrg'
        }
    },
    data () {
        return {}
    },
    created () {
        console.log('hello')
    },
    methods: {
        ...mapMutations(['setAuditParams', 'setSelectedInfo']),
        clientSelect () {
            if (this.type === 'getParentOrg') {
                // 向上选择
                selectDataClient({
                    SelectServiceToken: '/hr/org/getParentOrg', // 客户端对应方法名
                    IsSingleMode: true, // 是否单选 true 单选 false 多选
                    SelectedIDs: this.SelectedIDs, // 已选中id
                    Title: '选择申请单位' // 标题
                }).then(val => {
                    this.$emit('update:orgId', val[0].orgId)
                    this.$emit('update:orgName', val[0].orgName)
                    // this.setSelectedInfo(val)
                    // openAppClient('/showSelectedData', '选择结果', function () {})
                }).catch(()=>{
                    this.$emit('update:orgId', '')
                    this.$emit('update:orgName', '')
                })
            } else {
                // 向下选择
                // this.setSelectedInfo(this.SelectedIDs)
                // openAppClient('/showSelectedData', '选择结果', function () {})
                selectDataClient({
                    SelectServiceToken: '/hr/org/getChildrenOrg', // 客户端对应方法名
                    IsSingleMode: true, // 是否单选 true 单选 false 多选
                    SelectedIDs: this.SelectedIDs, // 已选中id
                    Title: '选择申请单位' // 标题
                }).then(val => {
                    this.$emit('update:orgId', val[0].orgId)
                    this.$emit('update:orgName', val[0].orgName)
                    // this.setSelectedInfo(val)
                    // openAppClient('/showSelectedData', '选择结果', function () {})
                }).catch(()=>{
                    this.$emit('update:orgId', '')
                    this.$emit('update:orgName', '')
                })
            }
        },
        noFocus () {
            this.$refs.noFocus.blur()
        }
    }
}
</script>

<style lang="less" scoped></style>
